﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ASPItalia.ModelVirtualCasting.Common;
using ASPItalia.ModelVirtualCasting.EntityFramework;
using ASPItalia.ModelVirtualCasting.ObjectModel;
using System.Diagnostics;

namespace ASPItalia.ModelVirtualCasting.EntityFramework.Test
{
	class Program
	{
		static void Main(string[] args)
		{
			ICandidateRepository repository = ApplicationContext.Current.Candidates;
			//AddUser();
			//WriteUser(ApplicationContext.Current.Users.GetAll());
			Stopwatch sw = new Stopwatch();
			sw.Start();
			WriteCandidate(repository.CreateQuery().DoNotTrack().GetAll());
			WriteCandidate(repository.CreateQuery().DoNotTrack().Include(c => c.JobLevel).GetAll());
			WriteCandidate(repository.CreateQuery().DoNotTrack().EnableLazyLoading().GetAll());
			sw.Stop();
			Console.WriteLine(sw.Elapsed);
			Console.ReadLine();
		}

		static void WriteCandidate(IQueryable<Candidate> candidates)
		{
			foreach (Candidate c in candidates)
			{
				Console.WriteLine("{0}-{1}", c.FirstName + c.LastName, (c.JobLevel == null) ? String.Empty : c.JobLevel.JobLevelName);
			}
		}

		static void WriteUser(IQueryable<User> users)
		{
			foreach (var u in users)
			{
				Console.WriteLine("{0}-{1}", u.Username, u.Email);
			}
		}

		static void AddUser()
		{
			try
			{
				User user = new User() { Email = "test@test.it", Password = "password", Username="username" + DateTime.Now.Ticks };
				ApplicationContext.Current.Users.InsertOnSubmit(user);
				ApplicationContext.Current.Users.SubmitChanges();
			}
			catch (Exception er)
			{
				throw er;
			}
		}
	}
}